<template>
  <div class="app-container">
    <el-form class="formList"
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="100px">
      <el-row>

        <el-form-item label="支付方式"
          prop="payMethod">
          <el-select v-model="payMethods"
            placeholder="请选择支付方式"
            clearable
            size="small"
            multiple
            style="width: 232px"
            @keyup.enter.native="handleQuery">
            <el-option v-for="dict in payMethodList"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue" />
          </el-select>
        </el-form-item>

        <el-form-item label="支付日期"
          prop="payTimeArray">
          <el-date-picker v-model="queryParams.payTimeArray"
            type="daterange"
            align="right"
            size="small"
            style="width: 232px"
            value-format="yyyy-MM-dd"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="门店"
          prop="storeIds">
          <el-select v-model="queryParams.storeIds"
            multiple
            placeholder="请选择门店列表"
            clearable
            size="small"
            style="width: 232px"
            @keyup.enter.native="handleQuery">
            <el-option v-for="dict in storeInFoOptions"
              :key="dict.storeId"
              :label="dict.storeName"
              :value="dict.storeUid" />
          </el-select>
        </el-form-item>

        <el-form-item style="margin-left: 22px">
          <el-button type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh"
            size="mini"
            @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>

    </el-form>
    <el-row class="row-mbinfo">
      <el-col :span="1.5">
        <el-button type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport">导出</el-button>
      </el-col>

    </el-row>
    <div class="divTable">
      <el-table border
        v-loading="loading"
        :data="dataList">
        <el-table-column label="订单类型"
          align="center"
          prop="orderType"
          min-width="100px" />
        <el-table-column label="订单号"
          align="center"
          prop="orderNo"
          min-width="160px" />
        <el-table-column label="客户昵称"
          align="center"
          prop="customerName"
          min-width="120"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="电话"
          align="center"
          prop="phone"
          min-width="140">
        </el-table-column>
        <el-table-column label="客户编号"
          align="center"
          prop="customerNo"
          min-width="120"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="客户名称"
          align="center"
          prop="contactName"
          min-width="120"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="商品名称"
          align="center"
          prop="proName"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="SKU"
          align="center"
          prop="skuName"
          min-width="120px"
          show-overflow-tooltip />
        <el-table-column label="购买数量"
          align="center"
          prop="proNumber"
          min-width="100px" />
        <el-table-column label="商品单价"
          align="center"
          prop="proPrice"
          min-width="100px" />
        <el-table-column label="运费金额"
          align="center"
          prop="freightPrice"
          min-width="100px" />
        <el-table-column label="商品金额"
          align="center"
          prop="proAmount"
          min-width="100px" />
        <el-table-column label="优惠金额"
          align="center"
          prop="proCouponAmount"
          min-width="100px" />
        <el-table-column label="会员折扣"
          align="center"
          prop="proDiscountAmount"
          min-width="100px" />
        <el-table-column label="现金支付"
          align="center"
          prop="money"
          min-width="100px" />
        <el-table-column label="金币"
          align="center"
          prop="gold"
          min-width="100px" />
        <el-table-column label="银币"
          align="center"
          prop="silver"
          min-width="100px" />
        <el-table-column label="菠萝派"
          align="center"
          prop="score"
          min-width="100px" />
        <el-table-column label="支付方式"
          align="center"
          prop="payMethodStr"
          min-width="120px" />
        <el-table-column label="订单实收现金"
          align="center"
          prop="orderMoney"
          min-width="140px" />
        <el-table-column label="订单状态"
          align="center"
          prop="orderStatus"
          min-width="100px" />
        <el-table-column label="支付时间"
          align="center"
          prop="payTime"
          min-width="160px" />
        <el-table-column label="买家备注"
          align="center"
          prop="buyMes"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="服务备注"
          align="center"
          prop="remark"
          min-width="160px"
          show-overflow-tooltip />
        <el-table-column label="门店名称"
          align="center"
          prop="storeName"
          min-width="160px"
          show-overflow-tooltip />
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

  </div>
</template>

<script>
import {
  selectGroup
} from "@/api/platform/store"
import {
  financeOrder
} from "@/api/finance/finance"

export default {
  name: "Order",
  data () {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payMethod: '',
        payTimeArray: [],
        storeIds: [],
      },
      payMethods: [],
      dataList: [],
      payMethodList: [],
      storeInFoOptions: [],
    };
  },
  created () {
    this.getDicts("order_pay_method").then((response) => {
      this.payMethodList = response.data;
    });
    selectGroup().then(response => {
      this.storeInFoOptions = response.data || [];
    });
    this.getList();
  },
  methods: {
    getList () {
      this.loading = true;
      financeOrder(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.dataList.forEach(item => {
          if (item.payMethod) {
            let val = this.payMethodList.filter(v => v.dictValue == item.payMethod)
            if (val[0]) {
              item.payMethodStr = val[0].dictLabel
            } else {
              item.payMethodStr = ''
            }
          }
        })
        this.total = response.total;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery () {
      if (this.payMethods.length > 0) {
        this.queryParams.payMethod = this.payMethods.join(',')
      } else {
        this.queryParams.payMethod = null
      }

      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.payMethods = []
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport () {
      let times = new Date().getTime()

      this.download(
        "prod-api/finance/orderExport",
        {
          ...this.queryParams,
        },
        `订单报表-${times}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
